package jxl;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;

public class JxlTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		WritableWorkbook book=null;
		String filename="C:/测试.xls";
		try{
			book = Workbook.createWorkbook(new File(filename));
			WritableSheet sheet = book.createSheet("第一页", 0);
			//标题
			JxlUtil.mergeCells(sheet, 0, 1, 5, 1);
			JxlUtil.setRowView(sheet, 1, 600);
			Label label = new Label(0, 1, "test",JxlUtil.getWCFormat(JxlUtil.getWFont(16, true),false));
			sheet.addCell(label);
			//表格头部
			List<String> headerList=getHeaderList();
			JxlUtil.addTableHeader(sheet, 0, 2, headerList, JxlUtil.getWCFormat(JxlUtil.getWFont(12,true)),20,500);
			//表格内容
			JxlUtil.addTable(sheet, 0, 3, getContentList(), JxlUtil.getWCFormat(JxlUtil.getWFont(12)), 
					"title1,title2,title3,title4,title5,title6");
			//添加图片
			JxlUtil.addImage(sheet, 0, 7, 3, 15, "E:/Workspaces/JavaUtil/test.png");
			//写出
			book.write();
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			JxlUtil.closeQuietly(book);
		}
	}

	private static List<String> getHeaderList(){
		List<String> headerList=new ArrayList<String>();
		headerList.add("title1");headerList.add("title2");headerList.add("title3");
		headerList.add("title4");headerList.add("title5");headerList.add("title6");
		return headerList;
	}
	
	private static List<Person> getContentList(){
		List<Person> contentList=new ArrayList<Person>();
		Person person=new Person();
		person.setTitle1("a1");
		person.setTitle2("b1");
		person.setTitle3("c1");
		person.setTitle4("d1");
		person.setTitle5("e1");
		person.setTitle6("f1");
		contentList.add(person);
		person=new Person();
		person.setTitle1("a2");
		person.setTitle2("b2");
		person.setTitle3("c2");
		person.setTitle4("d2");
		person.setTitle5("e2");
		person.setTitle6("f2");
		contentList.add(person);
		person=new Person();
		person.setTitle1("a3");
		person.setTitle2("b3");
		person.setTitle3("c3");
		person.setTitle4("d3");
		person.setTitle5("e3");
		person.setTitle6("f3");
		contentList.add(person);
		return contentList;
		
	}
}
